extends Sprite2D
var value = 0

# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	pass
	
func get_value():
	return value

func set_value(value:int):
	get_node("back_ground/CenterContainer/Label").text = "%d" % value if value != 0 else ""
	self.value = value	
	set_color(value)


func set_color(value:int):
	var value_level = [
		Color8(255,255,255,0),
		Color8(220,170,116),
		Color8(12,170,116),
		Color8(220,55,116),
		Color8(22,12,99),
		Color8(120,70,88),
		Color8(33,88,99),
		Color8(222,222,88),
		Color8(220,111,22),
		Color8(220,3,45)
	]
	var setted = Color8(0,0,0,255)
	for i in range(0,value_level.size()):
		if value <= (1 << i):
			setted = value_level[i]
			break
	$back_ground.set_color(setted)
	set_abstract_font_color(setted)
	

func set_abstract_font_color(color:Color):
	var r = (color.r8 + 123) % 255
	var g = (color.g8 + 123) % 255
	var b = (color.b8 + 123) % 255
	get_node("back_ground/CenterContainer/Label").set("theme_override_colors/font_color", Color8(r,g,b,255))
